Skip to content

Conversation

@janoma
Copy link
Contributor

@janoma janoma commented Jun 2, 2016

This should take care of #62.

sum_numbers(Collection const& collection)
{
using ReturnType = typename Collection::value_type;
return std::accumulate(std::begin(collection), std::end(collection), static_cast<ReturnType>(0));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why use std::begin and std::end instead of collection.begin() and collection.end()?

Copy link
Contributor Author

@janoma janoma Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a generic free function that will call what you expect without any overload (for any decent compiler). It also support arrays, so you can call sum_numbers on an array as well. And of course you can call it with any non-STL container for which an appropriate overload of the functions has been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants